--bang LinkWeb
go
create proc selectLinkWeb
as
begin
	select * from LinkWeb
end

go
create proc addLinkWeb
@LinkWebName nvarchar(100),
@LinkWebSite nvarchar(100)
as
begin
	insert into LinkWeb values(@LinkWebName,@LinkWebSite)
end

go
create proc selectLinkWebById
@LinkWebID int
as
begin
	select * from LinkWeb where LinkWebID=@LinkWebID
end

go
create proc updateLinkWeb
@LinkWebID int,
@LinkWebName nvarchar(100),
@LinkWebSite nvarchar(100)
as
begin
	update LinkWeb set LinkWebName=@LinkWebName,LinkWebSite=@LinkWebSite where LinkWebID=@LinkWebID
end

go
create proc removeLinkWeb
@LinkWebID int
as
begin
	delete LinkWeb where LinkWebID=@LinkWebID	
end
--tao phan trang cho bang LinkWeb
go
create PROCEDURE [dbo].[spLinkWeb_PhanTrang]
@currPage int,
@recodperpage int,
@Pagesize int
AS
Begin
    Begin
    WITH s AS
    (
        SELECT ROW_NUMBER()
                        OVER(ORDER BY LinkWebID) 
						AS RowNum,
                        LinkWebID,
                        LinkWebName,
                        LinkWebSite
        FROM LinkWeb
    )
    Select * From s
    Where RowNum Between
                (@currPage - 1)*@recodperpage+1
                        AND @currPage*@recodperpage
    END
    -- Tinh tong so ban ghi
    DECLARE @Tolal int
    SELECT @Tolal=Count(*) FROM dbo.LinkWeb
    EXEC spPhanTrangSQL 
			@Tolal, 
			@currPage, 
			@Pagesize, 
			@recodperpage
END
